# pylint: disable-msg=E1101
"""
@author: Sergiy Tsymbalyuk
"""

import logging

from pylons import url
from pylons.i18n import lazy_ugettext as _

from repoze.what.plugins.pylonshq import ControllerProtector
from repoze.what.predicates import Any, All, in_group

from chowa.lib.site.crud import FlatCrudController
from chowa.model.organization import Division

from hrms.lib.base import BaseController, render, Session
from hrms.lib.predicates import from_district

log = logging.getLogger(__name__)

@ControllerProtector(Any(All(in_group('hrms.hr'), from_district()),
                         in_group('hrms.administrators')))
class DivisionsController(FlatCrudController):
    __model__ = Division
    __columns__ = ['code', 'name', 'is_disabled']
    __edit_columns__ = ['name', 'genitive', 'short_name', 'code', 'district', 'is_disabled']
    __order__ = ['is_disabled', 'code', 'name']
    __bool_values__ = {'is_disabled': (_('discontinued'), '', '')}
    __view_url__ = ('name', lambda record_id: url(controller='organization',
                                                  action='division',
                                                  id=record_id))
